package com.ruoyi.report.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.utils.UrlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.report.mapper.XlkjReportMapper;
import com.ruoyi.report.domain.XlkjReport;
import com.ruoyi.report.service.IXlkjReportService;

/**
 * 举报投诉Service业务层处理
 *
 * @author wang
 * @date 2022-01-15
 */
@Service
public class XlkjReportServiceImpl implements IXlkjReportService
{
    @Autowired
    private XlkjReportMapper xlkjReportMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询举报投诉
     *
     * @param id 举报投诉主键
     * @return 举报投诉
     */
    @Override
    public XlkjReport selectXlkjReportById(Long id)
    {
        XlkjReport report = xlkjReportMapper.selectXlkjReportById(id);
        //上报者信息
        SysUser sysUser = sysUserMapper.selectUserById(report.getUserId());
        sysUser.setAvatar(UrlUtils.getUrl() + sysUser.getAvatar());
        report.setSysUser(sysUser);
        //答复者信息
        if(report.getUpdateBy() != null && report.getUpdateBy().length() != 0){
            SysUser sysUser1 = sysUserMapper.selectUserById(Long.valueOf(report.getUpdateBy()));
            sysUser1.setAvatar(UrlUtils.getUrl() + sysUser1.getAvatar());
            report.setSysUserUpdateBy(sysUser1);
        }
        return report;
    }

    /**
     * 查询举报投诉列表
     *
     * @param xlkjReport 举报投诉
     * @return 举报投诉
     */
    @Override
    public List<XlkjReport> selectXlkjReportList(XlkjReport xlkjReport)
    {
        List<XlkjReport> xlkjReports = xlkjReportMapper.selectXlkjReportList(xlkjReport);
        for(XlkjReport report:xlkjReports){
            SysUser sysUser = sysUserMapper.selectUserById(report.getUserId());
            sysUser.setAvatar(UrlUtils.getUrl() + sysUser.getAvatar());
            report.setSysUser(sysUser);
        }
        return xlkjReports;
    }

    /**
     * 新增举报投诉
     *
     * @param xlkjReport 举报投诉
     * @return 结果
     */
    @Override
    public int insertXlkjReport(XlkjReport xlkjReport)
    {
        xlkjReport.setCreateTime(DateUtils.getNowDate());
        return xlkjReportMapper.insertXlkjReport(xlkjReport);
    }

    /**
     * 修改举报投诉
     *
     * @param xlkjReport 举报投诉
     * @return 结果
     */
    @Override
    public int updateXlkjReport(XlkjReport xlkjReport)
    {
        xlkjReport.setUpdateTime(DateUtils.getNowDate());
        xlkjReport.setUpdateBy(SecurityUtils.getUserId()+"");
        return xlkjReportMapper.updateXlkjReport(xlkjReport);
    }

    /**
     * 批量删除举报投诉
     *
     * @param ids 需要删除的举报投诉主键
     * @return 结果
     */
    @Override
    public int deleteXlkjReportByIds(Long[] ids)
    {
        return xlkjReportMapper.deleteXlkjReportByIds(ids);
    }

    /**
     * 删除举报投诉信息
     *
     * @param id 举报投诉主键
     * @return 结果
     */
    @Override
    public int deleteXlkjReportById(Long id)
    {
        return xlkjReportMapper.deleteXlkjReportById(id);
    }
}
